# -*- coding: utf-8 -*-
"""
Created by edc on 2020/7/28
"""

import tensorflow as tf
import operation.test.DL as DL
from tensorflow import keras
from sklearn.model_selection import train_test_split

#####################        主方法           #########################
strategy = tf.distribute.MirroredStrategy()
print("Number of devices: {}".format(strategy.num_replicas_in_sync))

with strategy.scope():
    model = DL.get_model('ResNet50')
    model.compile(
        optimizer='rmsprop',
        loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
        metrics=[keras.metrics.SparseCategoricalAccuracy()],
        loss_weights=None,
        sample_weight_mode=None,
        weighted_metrics=None,
    )
    model.summary()

# 导入数据
data_path = '/root/dog_vs_cat_raw'
datas, labels = DL.load_dataset(data_path)

# 数据训练集和测试集分割
(trainX, testX, trainY, testY) = train_test_split(datas, labels, test_size=0.25, random_state=42)

model.fit(x=trainX, y=trainY, epochs=1, validation_data=(testX, testY))
